using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace NuoYan.Extension
{
    public static class ListExtension
    {
        /// <summary>
        /// 此方法当数量超出List本身的数量时，会Pop一个空字符占位  注意判空处理
        /// </summary>
        /// <param name="list"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Pop<T>(this List<T> list)
        {
            while (list.Count > 0)
            {
                T item = list[list.Count - 1];
                list.RemoveAt(list.Count - 1);
                return item;
            }
            return default(T);
        }
        /// <summary>
        /// 将List<string>中的元素以指定分隔符拼接成字符串
        /// </summary>
        /// <param name="list"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        public static string Join(this IList<string> list, string separator)
        {
            // 处理null情况
            if (list == null)
                throw new ArgumentNullException(nameof(list));
            if (separator == null)
                separator = string.Empty;

            // 空列表返回空字符串
            if (list.Count == 0)
                return string.Empty;

            return string.Join(separator, list);
        }
    }
}

